﻿using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Wpf2.Models;
using Wpf2.ViewModels;

namespace Wpf2.Views
{
    /// <summary>
    /// Interaction logic for ManageInventoryEditPrint.xaml
    /// </summary>
    public partial class ManageInventoryEditPrint
    {
        readonly IList<int> _hideColumns;
        readonly NotifiableCollection<Products> _products;
        public ManageInventoryEditPrint(IEnumerable<Products> products,IList<int> hideColumns)
        {
            InitializeComponent();
            _products = new NotifiableCollection<Products>();
            foreach (Products p in products)
            {
                _products.Add(p);
            }
            dtgProduct.DataContext = _products;
            foreach (var t in hideColumns)
            {
                dtgProduct.Columns[t].Visibility = Visibility.Hidden;
            }
            _hideColumns = new List<int>();
           foreach(var i in hideColumns) {
               _hideColumns.Add(i);
            }
        }

        private void DtgProductLoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = (e.Row.GetIndex() + 1).ToString(CultureInfo.InvariantCulture);
        }

        private void BtnPrintClick(object sender, RoutedEventArgs e)
        {
            IDictionary<string, string> param = new Dictionary<string, string>();
            param.Add("StoreName", txtStoreName.Text);
            param.Add("Address", txtAddress.Text);
            param.Add("Mobile", txtMobile.Text);
            param.Add("Phone", txtPhone.Text);
            param.Add("ProductId", "1");
            param.Add("ProductName", "1");
            param.Add("ProductDescription", "1");
            param.Add("ProductQuantity", "1");
            param.Add("ProductCostPrice", "1");
            param.Add("ProductCellPrice", "1");
            param.Add("ProductUnit", "1");
            param.Add("ProductCatalog", "1");
            foreach (var t in _hideColumns)
            {
                switch (t)
                { 
                    case 1:
                        param["ProductId"] = "0";
                        break;
                    case 2:
                        param["ProductName"] = "0";
                        break;
                    case 3:
                        param["ProductDescription"] = "0";
                        break;
                    case 4:
                        param["ProductQuantity"] = "0";
                        break;
                    case 5:
                        param["ProductCostPrice"] = "0";
                        break;
                    case 6:
                        param["ProductCellPrice"] = "0";
                        break;
                    case 7:
                        param["ProductUnit"] = "0";
                        break;
                    case 8:
                        param["ProductCatalog"] = "0";
                        break;
                }
            }
            var r = new CrystalReportInventoryViewer(_products.ToList(), param);
            r.ShowDialog();
        }
    }
}
